﻿@{
    Layout = null;
}
<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />

<div class="layui-row">
    <div class="layui-col-xs3" style="background-color:aquamarine">
        <div class="grid-demo grid-demo-bg1" style="background-color:aqua">
            <div id="typetree"></div>
        </div>
    </div>
    <div class="layui-col-xs9" style="background-color:aqua">
        <div class="grid-demo" style="background-color:aquamarine">6/12</div>
    </div>
</div>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>

<script>
    layui.use(function(){
      var tree = layui.tree;
      var layer = layui.layer;
      // 模拟数据
      var data = [];

      function getTypeTree(){
          $.ajax({
              url:'/MaterialManagement/GetMaterialType',
              type:'get',
              dataType:'json',
              success:function(res){
                  data = res
                  console.log(data)
              }
          })
      }

      getTypeTree()
      selTree()

      function selTree (){
          console.log(11)
          // 渲染
          tree.render({
            elem: '#typetree',
            data: data,
            onlyIconControl: true,  // 是否仅允许节点左侧图标控制展开收缩
            click: function(obj){
              layer.msg(JSON.stringify(obj.data));
            }
          });
      }

    });

</script>